<?php

/**
 * current_academic_year actions.
 *
 * @package    sf_sandbox
 * @subpackage current_academic_year
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class current_academic_yearActions extends sfActions {

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
    public function executeIndex(sfWebRequest $request) {
        $this->form = new currentAcademicYearForm();

        if ($request->getMethod() == 'POST') {
            $year = $request->getParameter('year');
            $semester = $request->getParameter('semester');

            $q = Doctrine_Query::create()->update('AcademicYear')->where('id <> ?', $year)->set('current', '?', '0');
            $q->execute();

            $q = Doctrine_Query::create()->update('AcademicYear')->where('id = ?', $year)->set('current', '?', '1')->set('semester', '?', $semester);
            $q->execute();

            sfContext::getInstance()->getConfiguration()->loadHelpers(array('i18n'));

//            $this->getUser()->setFlash('notice', __('current year saved successfully'));
            $this->redirect('current_academic_year/index');
        }
    }

}
